import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import Home from '../views/Home.vue';

Vue.use(VueRouter);

const routes: Array<RouteConfig> = [
    {
        path: '/',
        name: 'home',
        component: Home,
        children: [],
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/Login.vue'),
    },
];

const router = new VueRouter({
    routes,
});

export function isLogin() {
    return false;
}

router.beforeEach((to, from, next) => {
    if (localStorage['login-time']
        && Date.now() - parseInt(localStorage['login-time']) < 30 * 60 * 1000
        || to.name === 'login') {
        next();
    } else {
        router.push({
            name: 'login',
        });
    }
});

export default router;
